package com.liuugoqing.behavioral.visitor.staticdispatch;

import org.junit.Test;

/**
 * 静态分派(Static Dispatch) 发生在编译时期，分派根据静态类型信息发生。
 * 静态分派对于我们来说并不陌生，方法重载就是静态分派
 * @Author : liugq
 * @Date : 2022/7/15 21:45
 * @See : 参考类
 * @Since： JDK1.8
 * @Version : 1.0
 */
public class Client {
    public class Animal {
    }

    public class Dog extends Animal {
    }

    public class Cat extends Animal {
    }

    public class Execute {
        public void execute(Animal a) {
            System.out.println("Animal");
        }

        public void execute(Dog d) {
            System.out.println("dog");
        }

        public void execute(Cat c) {
            System.out.println("cat");
        }
    }

    @Test
    public void test() throws Exception{
        Animal a = new Animal();
        Animal a1 = new Dog();
        Animal a2 = new Cat();

        Execute exe = new Execute();
        exe.execute(a);
        exe.execute(a1);
        exe.execute(a2);
    }

}
